package org.ielts.action;

import static com.yifeng.struts2.ResultParameters.*;
import static com.yifeng.struts2.ResultConstants.*;
import java.io.IOException;
import java.util.Random;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.yifeng.chart.DataSet;
import com.yifeng.chart.Set;
import com.yifeng.chart.SingleSeries;
import com.yifeng.chart.fusion.FusionDataXmlCreater;
import com.yifeng.modules.annotations.Operation;

public class ReportAction {

	@Operation(result = XML)
	public String doIdelLesson() throws ParserConfigurationException, SAXException, IOException {		
		SingleSeries singleSeries = new SingleSeries();
		singleSeries.setSeriesName("测试");

		DataSet dataSet = new DataSet();

		Set set = new Set();
		set.setLabel("空课");
		set.setValue("2");
		dataSet.add(set);

		set = new Set();
		set.setLabel("非空课");
		set.setValue("22");
		dataSet.add(set);

		singleSeries.setDataSet(dataSet);

		String template = "<chart caption='空课占比'></chart>";
		Document document = FusionDataXmlCreater.getSingleSeriesChart(singleSeries, template);

		setDocument(document);
		return XML;
	}

	@Operation(result = XML)
	public String doLessonCount() throws ParserConfigurationException, SAXException, IOException {

		SingleSeries singleSeries = new SingleSeries();
		singleSeries.setSeriesName("测试");

		DataSet dataSet = new DataSet();

		Set set = new Set();
		set.setLabel("3-11");
		set.setValue("3");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-12");
		set.setValue("3");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-13");
		set.setValue("4");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-14");
		set.setValue("4");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-15");
		set.setValue("4");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-16");
		set.setValue("4");
		dataSet.add(set);

		set = new Set();
		set.setLabel("3-17");
		set.setValue("0");
		dataSet.add(set);

		singleSeries.setDataSet(dataSet);

		String template = "<chart caption='每日课时安排'></chart>";
		Document document = FusionDataXmlCreater.getSingleSeriesChart(singleSeries, template);

		setDocument(document);
		return XML;
	}

	@Operation(result = XML)
	public String studentLeavingByMonth() throws ParserConfigurationException, SAXException, IOException {
		SingleSeries singleSeries = new SingleSeries();

		DataSet dataSet = new DataSet();

		Random random = new Random();

		for (int i = 1; i <= 12; i++) {

			int num = random.nextInt(100);
			num += 50;

			Set set = new Set();
			set.setLabel(i + "月内");
			set.setValue(String.valueOf(num));
			dataSet.add(set);
		}

		singleSeries.setDataSet(dataSet);

		String template = "<chart caption='每月学员结课统计'></chart>";
		Document document = FusionDataXmlCreater.getSingleSeriesChart(singleSeries, template);

		setDocument(document);
		return XML;
	}

	@Operation(result = XML)
	public String studentCountByMonth() throws ParserConfigurationException, SAXException, IOException {
		SingleSeries singleSeries = new SingleSeries();
		DataSet dataSet = new DataSet();

		Random random = new Random();

		for (int i = 1; i <= 12; i++) {

			int num = random.nextInt(200);
			num += 50;

			Set set = new Set();
			set.setLabel(i + "月");
			set.setValue(String.valueOf(num));
			dataSet.add(set);
		}

		singleSeries.setDataSet(dataSet);

		String template = "<chart caption='每月在读学员统计'></chart>";
		Document document = FusionDataXmlCreater.getSingleSeriesChart(singleSeries, template);

		setDocument(document);
		return XML;
	}

}
